<extend name="./Application/Admin/View/Layout/application.html"/>
<block name="css">
    <link rel="stylesheet" href="__PUBLIC__/assets/admin/css/common.css">
</block>

    <!-- content start -->
    <block name="content">
        <div class="admin-content">

            <div class="am-cf am-padding">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">新增用户</strong> /
                    <small>Create User</small>
                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-12">
                    <div class="am-tab-panel">
                        <form class="am-form" >
                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    用户名
                                </div>
                                <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                                    <input type="text" class="am-input-sm" id="username" name="username">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    邮箱
                                </div>
                                <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                                    <input type="text" class="am-input-sm" id="email" name="email">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    手机号
                                </div>
                                <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                                    <input type="text" class="am-input-sm" id="mobile" name="mobile">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    新密码
                                </div>
                                <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                                    <input type="password" class="am-input-sm" id="password" name="password">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    确认密码
                                </div>
                                <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                                    <input type="password" class="am-input-sm" id="check_password" name="check_password">
                                </div>
                            </div>

                            <div class="am-g am-margin-top">
                                <div class="am-u-sm-4 am-u-md-3 am-text-right">
                                    选择用户组
                                </div>
                                <div class="am-u-sm-8 am-u-md-4 am-u-end col-end">
                                    <volist name="groups" id="group">
                                        <label class="am-checkbox-inline">
                                            <input type="checkbox" value="{{$group.id}}" class="checked_id" name="group_id[]"/>{{$group.title}}
                                        </label>
                                    </volist>
                                </div>
                            </div>

                            <div class="am-margin">
                                <button class="submit am-btn am-btn-primary">保 存</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </block>
    <!-- content end -->

<block name="js">
    <script src="__PUBLIC__/vendor/assets/js/jquery.min.js"></script>
    <script>
        $(function () {
            $('.submit').click(function () {
                var info = $("input").serialize();
//                var info = {
//                    username: $('#username').val(),
//                    email: $('#email').val(),
//                    mobile: $('#mobile').val(),
//                    password: $('#password').val(),
//                    check_password: $('#check_password').val(),
//                    group_ids: $('.checked_id:checked').serialize(),
//                };

//                if (info.username.length < 3) {
//                    alert('您输入的用户名不能小于3个长度！');
//                    return false;
//                }
//                if (info.password.length < 6) {
//                    alert('您输入的密码不能小于6位！')
//                    return false;
//                }
//                var patter = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
//                if (!patter.test(info.email)) {
//                    alert('您输入的邮箱格式不正确！');
//                    return false;
//                }
//                var regs = /^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$/;
//                if (!regs.test(info.mobile)) {
//                    alert('您输入的电话号码格式不正确！');
//                    return false;
//                }
//                if (info.check_password != info.password) {
//                    alert('两次密码输入不一致！');
//                    return false;
//                }
//                if (info.group_ids = "") {
//                    alert('您至少选择一项权限！');
//                    return false;
//                }
                $.ajax({
                    type:'post',
                    url:"{{:U('add_user')}}",
                    data:info,
                    success:function (file) {
                        if(file.status==1){
                            alert(file.msg);
                            location.href = "{{:U('AuthSet/user_manage')}}"
                        }else{
                            alert(file.msg);
                            return false;
                        }

                    }
                });
                return false;
            })
        })
    </script>
</block>

